var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/baseComponent/checkbox.tsx
var checkbox_exports = {};
__export(checkbox_exports, {
  Checkbox: () => Checkbox,
  CheckboxGroup: () => CheckboxGroup,
  Switch: () => Switch
});
module.exports = __toCommonJS(checkbox_exports);
var import_antd = require("antd");
var import_util = require("../util");
function getComp(Comp) {
  return class extends import_util.IUPComponent {
    constructor(props) {
      super(props);
      this.onCompChange = (e) => {
        var _a;
        const { checkedValue = 1, unCheckedValue = 0 } = this.props;
        const value = ((_a = e.target) == null ? void 0 : _a.checked) ?? e ? checkedValue : unCheckedValue;
        if (this.props.hasOwnProperty("checked") || this.props.hasOwnProperty("value")) {
          const lastValue = this.state.value;
          this.state.value = value;
          this._propOnChangeHandler(value, lastValue).then((r) => {
            if (r === false) {
              this.state.value = lastValue;
            }
          });
        } else {
          this.setValue(value);
        }
        this.innerNotify([value], "onChange").then();
      };
      this.state.value = props.defaultChecked;
      this.state.loading = false;
    }
    static getDerivedStateFromProps(nextProps, prevState) {
      return import_util.IUPComponent.propsToState(nextProps, prevState, ["checked|value", "value"]);
    }
    async _propOnChangeHandler(value, lastValue = void 0) {
      var _a, _b;
      const isSwitch = Comp === Switch;
      const p = (_b = (_a = this.props).onChange) == null ? void 0 : _b.call(_a, value);
      let ret = true;
      if (import_util.iup.isPromise(p)) {
        try {
          isSwitch && this.setState({ loading: true });
          ret = await p;
        } catch (e) {
          console.log(e);
        } finally {
          isSwitch && this.setState({ loading: false });
        }
      } else {
        ret = p;
      }
      if (ret === false && lastValue !== void 0) {
        this.state.value = lastValue;
      }
      return ret;
    }
    setValue(value, cb) {
      if (this.state.value === value) {
        return;
      }
      this.setState(
        (prev) => ({ ...prev, value }),
        () => {
          this._propOnChangeHandler(value).then();
          cb && cb(value);
        }
      );
    }
    getValue() {
      return this.state.value;
    }
    render() {
      const {
        defaultChecked,
        checked,
        value,
        bordered,
        // 表单元素公有属性，checkbox没有，需要过滤，否则antd会报警告
        onChange,
        checkedValue = 1,
        unCheckedValue = 0,
        observer,
        allowClear,
        ...others
      } = this.props;
      const newProps = { ...others };
      if (Comp === Switch && this.state.hasOwnProperty("loading")) {
        newProps.loading = this.state.loading;
      }
      return /* @__PURE__ */ React.createElement(
        Comp,
        {
          ref: this.outRef,
          checked: this.state.value === checkedValue,
          ...newProps,
          onChange: this.onCompChange
        }
      );
    }
  };
}
var Checkbox = (0, import_util.compHoc)(getComp(import_antd.Checkbox), "Checkbox");
var Switch = (0, import_util.compHoc)(getComp(import_antd.Switch), "Switch");
var CheckboxGroup = (0, import_util.compHoc)(
  class extends import_util.IUPComponent {
    constructor(props) {
      super(props);
      this.onCheckBoxChange = (value) => {
        if (this.props.hasOwnProperty("value")) {
          this.state.value = value;
          this.props.onChange && this.props.onChange(value);
        } else {
          this.setValue(value);
        }
        this.innerNotify([value], "onChange").then();
      };
      this.state.value = props.defaultValue;
    }
    static getDerivedStateFromProps(nextProps, prevState) {
      return import_util.IUPComponent.propsToState(nextProps, prevState, ["value"]);
    }
    setValue(value) {
      this.setState(
        (prev) => ({ ...prev, value }),
        () => {
          this.props.onChange && this.props.onChange(value);
        }
      );
    }
    getValue() {
      return this.state.value;
    }
    render() {
      const {
        bordered,
        // 表单元素公有属性，checkbox没有，需要过滤，否则antd会报警告
        defaultValue,
        data,
        options,
        value,
        onChange,
        observer,
        allowClear,
        ...others
      } = this.props;
      return /* @__PURE__ */ React.createElement(
        import_antd.Checkbox.Group,
        {
          options: options || data,
          value: this.state.value,
          ...others,
          onChange: this.onCheckBoxChange
        }
      );
    }
  },
  "CheckboxGroup"
);
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  Checkbox,
  CheckboxGroup,
  Switch
});
